<?php

class Permission_Controller_Admincp_Role_Edit extends Nuo_Controller_Admincp
{
	function execute($request)
	{
		$id = $request -> getParam('role_id');

		$table = Nuo::getTable('permission/role');

		$form = Nuo::getObject('permission/admincp/role/edit', 'form');

		$item = NULL;

		if ($id)
		{
			$item = $table -> find($id) -> current();
		}

		if ($request -> isGet() && $item)
		{
			$form -> setData($item -> toArray());
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item -> fromArray($data);

			$item -> save();

			Nuo_Messenger::instance()->add(Intl::__('Updated!'));

			return  'nuo.refresh();';
			return;
		}

		return  Nuo::getView()->render('core/view/controller/admincp/edit', array('form' => $form));
	}

}
